package com.littlebee.storysuper.utils;

import android.content.Context;
import android.os.Looper;
import android.text.TextUtils;
import android.widget.Toast;
import com.littlebee.storysuper.BaseApplication;


/**
 * 作者：liaoyong on 2016/7/11 13:34
 * 邮箱：liaoyong@tuliu.com
 * 描述：提示工具类
 */
public class ToastUtil {

    private static Toast longToast;
    private static Toast shortToast;
    private static Toast customDurationToast;


    public static Toast displayLongToast(final String text){
        new Thread() {
            @Override
            public void run() {
                Looper.prepare();
                if(longToast != null){
                    longToast.cancel();
                }
                longToast = Toast.makeText(BaseApplication.getInstance(), text, Toast.LENGTH_LONG);
                longToast.show();
                Looper.loop();
            }
        }.start();
        return longToast;
    }

    public static Toast displayShortToast(final String text){
        new Thread() {
            @Override
            public void run() {
                Looper.prepare();
                if(shortToast != null){
                    shortToast.cancel();
                }
                shortToast = Toast.makeText(BaseApplication.getInstance(), text, Toast.LENGTH_SHORT);
                shortToast.show();
                Looper.loop();
            }
        }.start();
        return shortToast;
    }

    public static Toast displayShortToast(final int stringid){
        new Thread() {
            @Override
            public void run() {
                Looper.prepare();
                if(shortToast != null){
                    shortToast.cancel();
                }
                shortToast = Toast.makeText(BaseApplication.getInstance(), BaseApplication.getInstance().getString(stringid), Toast.LENGTH_SHORT);
                shortToast.show();
                Looper.loop();
            }
        }.start();
        return shortToast;
    }

    public static Toast displayCustomDurationToast(final String text , final int duration){
        new Thread(){
            @Override
            public void run() {
                Looper.prepare();
                if(customDurationToast != null){
                    customDurationToast.cancel();
                }
                customDurationToast = Toast.makeText(BaseApplication.getInstance(), text, duration);
                customDurationToast.show();
                Looper.loop();
            }
        }.start();
        return customDurationToast;
    }
}
